home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 2.iso / STUTTGART / TEMP / GNU / bison / TieinRecov < prev    next >
Text File  |  1995-06-28  |  2KB  |  61 lines

  1. Tie-in Recovery
  2. Previous: <Lexical Tie-ins=>LexicalTie> * Next: <Debugging=>Debugging> * Up: <Context Dependency=>ContextDep>
  3.  
  4. #Wrap on
  5. {fH3}Lexical Tie-ins and Error Recovery{f}
  6.  
  7. Lexical tie-ins make strict demands on any error recovery rules you have.
  8. \*Note <Error Recovery=>ErrorRecov>.
  9.  
  10. The reason for this is that the purpose of an error recovery rule is to
  11. abort the parsing of one construct and resume in some larger construct.
  12. For example, in C-like languages, a typical error recovery rule is to skip
  13. tokens until the next semicolon, and then start a new statement, like this:
  14.  
  15. #Wrap off
  16. #fCode
  17. stmt:   expr ';'
  18.         | IF '(' expr ')' stmt \{ … \}
  19.         …
  20.         error ';'
  21.                 \{ hexflag = 0; \}
  22.         ;
  23. #f
  24. #Wrap on
  25.  
  26. If there is a syntax error in the middle of a {fEmphasis}hex ({fStrong}expr{f}){f}
  27. construct, this error rule will apply, and then the action for the
  28. completed {fEmphasis}hex ({fStrong}expr{f}){f} will never run.  So {fCode}hexflag{f} would
  29. remain set for the entire rest of the input, or until the next {fCode}hex{f}
  30. keyword, causing identifiers to be misinterpreted as integers.
  31.  
  32. To avoid this problem the error recovery rule itself clears {fCode}hexflag{f}.
  33.  
  34. There may also be an error recovery rule that works within expressions.
  35. For example, there could be a rule which applies within parentheses
  36. and skips to the close-parenthesis:
  37.  
  38. #Wrap off
  39. #fCode
  40. expr:   …
  41.         | '(' expr ')'
  42.                 \{ $$ = $2; \}
  43.         | '(' error ')'
  44.         …
  45. #f
  46. #Wrap on
  47.  
  48. If this rule acts within the {fCode}hex{f} construct, it is not going to abort
  49. that construct (since it applies to an inner level of parentheses within
  50. the construct).  Therefore, it should not clear the flag: the rest of
  51. the {fCode}hex{f} construct should be parsed with the flag still in effect.
  52.  
  53. What if there is an error recovery rule which might abort out of the
  54. {fCode}hex{f} construct or might not, depending on circumstances?  There is no
  55. way you can write the action to determine whether a {fCode}hex{f} construct is
  56. being aborted or not.  So if you are using a lexical tie-in, you had better
  57. make sure your error recovery rules are not of this kind.  Each rule must
  58. be such that you can be sure that it always will, or always won't, have to
  59. clear the flag.
  60.  
  61.